package com.sxbang.bms.base.result;

import java.io.Serializable;
import java.util.List;

/**
 * @author lmm
 * @date 2019/3/28 0028  13:41.
 */
public class Results<T>  implements Serializable {

    int count;//数据数量
    String code;//代码
    String msg;//信息
    List<T> data;//返回数据
    T example;//任何类型条件


    public Results() {
    }
    public Results(String code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public Results(String code, String msg,T example) {
        super();
        this.code = code;
        this.msg = msg;
        this.example = example;
    }

    public Results(String code, String msg, int count, List<T> data) {
        super();
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }


    public static <T> Results<T> success() {
        return success("0", "请求成功", 0, null);
    }
    public static <T> Results<T> success(String msg) {
        return success("0", msg, 0, null);
    }

    public static <T> Results<T> success(int count, List<T> data) {
        return success("0", "请求成功", count, data);
    }

    public static <T> Results<T> success(T example) {
        return new Results<T>("0","请求成功",example);
    }

    public static <T> Results<T> success(String msg, int count, List<T> data) {
        return success("0", msg, count, data);
    }
    public static <T> Results<T> success(String code, String msg, int count, List<T> data) {
        return new Results<T>( code,  msg,  count,  data);
    }
    public static <T> Results<T> failure(ResultCode resultCode) {
        return new Results<T>( resultCode.getCode().toString(),  resultCode.getMessage(),  0,  null);
    }
    public static <T> Results<T> failure(String code, String msg) {
        return new Results<T>( code,  msg,  0,  null);
    }
    public static <T> Results<T> failure(String code, String msg, int count, List<T> data) {
        return new Results<T>( code,  msg,  count,  data);
    }

    public static Results ok() {
        return new Results();
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public T getExample() {
        return example;
    }

    public void setExample(T example) {
        this.example = example;
    }
}
